/**
 * @file
 * @auth zhaojing
 * @date 2016/11/24
 */

import './style.scss';
import tpl from './tpl.html';

import Vue from 'vue';
import modal from '../../../grsc-base/component/Modal.vue';
import help from '../../../grsc-base/component/Help.vue';
import Select from '../../../grsc-base/component/Select.vue';
import Popover from '../../../grsc-base/component/Popover.vue';
import Validator from '../../../grsc-base/component/Validator/main';
import VerifyCode from '../VerifyCode.vue';
import commonUtil from '../../common/util'
import {REG_EMAIL, REG_PHONE, REG_PAYPWD, REG_ID} from '../../../grsc-base/common/constants';
import {RULE_ASSET_PASSWORD_LENGTH, RULE_ASSET_PASSWORD_PATTERN, RULE_CODE_SEND, REG_PASSPORT} from '../../common/contants';
import lib from '../../common/lib';

import service from './service';

export default  Vue.extend({
    template: tpl,
    props: {
        onBindingSuccess: {
            type: Function,
            default() {
            }
        }
    },
    components: {
        modal,
        help,
        Popover,
        VerifyCode,
        Validator,
        VSelect: Select
    },
    created() {

    },
    mounted() {

    },
    watch: {},
    computed: {},
    data() {
        return {
            pwdForm:{
                'pay-password': '',
            },
            pwdRules:{
                password: {
                    tip: '',
                    minlength: 8,
                    minlengthTip: this.$t('common.ruleAssetPassLength'),
                    maxlength: 20,
                    maxlengthTip: this.$t('common.ruleAssetPassLength'),
                    pattern: REG_PAYPWD,
                    patternTip: this.$t('common.ruleAssetPassPattern'),
                    required: true,
                    requiredTip: this.$t('common.assetPassRequireTip')
                },
            },
            isRequesting: false
        }
    },
    methods: {
        setSelectVal(val){
            
        },
        onSendSuccess() {
            
        },
        onSendFail(rep) {
            
        },
        submit(){
            if(this.pwdRules.$checkAll()===false){
                return;
            }
            let header = {
                'pay-password': this.pwdForm.password
            };
            let param = {
                symbol:'USDT_'+localStorage.getItem('coinT'),
                orderNo:commonUtil.getUuid(),
            };

            service.match(param, header).done((rep) => {
                if (rep.code == window.CODE.SUCCESS) {
                    this.hide();
                    window.success(rep.msg);
                    this.onBindingSuccess();
                    window.location.reload();
                }else {      
                    window.error(rep.msg);
                }
            }).fail((rep) => {
                window.error(rep.msg);
                setTimeout(() => {
                    this.hide();
                }, 1500);
            }).always((rep) => {
                window.error(rep.msg);
            });
        },
        focusTips(){
           
        },
        blurTips(){
            
        },
        hide() {
            this.$emit('hide');
        }
    }

});
